<template>
  <div class="school">
    <h2>学校名称：{{name}}</h2>
    <h2>学校地址:{{address}}</h2>
  </div>
</template>

<script>
  import pubsub from 'pubsub-js'
  export default {
    name:'MySchool',
    props:['getSchoolName'],
    data(){
      return{
        name:'好学校真的好1234',
        address:'浦东新区',
      }
    },
    methods: {
      // 配合写法1
      demo(msgName,data){
        console.log('订阅hello:[',msgName,']，收到的数据',data)
      }
    },
    // 订阅
    mounted(){
      // 写法1
      // this.pubId = pubsub.subscribe('hello', this.demo)

      //写法2
      this.pubId = pubsub.subscribe('hello', (msgName,data)=>{
        console.log('订阅hello:[',msgName,']，收到的数据',data)
      })

    },
    
    // 取消订阅
    beforeDestroy () {
      // this.$bus.$off('hello')
      pubsub.unsubscribe(this.pubId)
    }
    
  }
</script>

<style scoped>
  .school{
    background-color: skyblue;
    padding:5px;
  }
</style>